package ar.com.tallerdos.smartdinner.sync;

import java.util.List;

import ar.com.tallerdos.smartdinner.business.AgregadoBusiness;
import ar.com.tallerdos.smartdinner.model.Agregado;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

public class GuarnicionesSincronizador extends Tarea {

    private static final String GUARNICIONES_SERVICE = "consultarGuarniciones.php";

    @Override
    public Integer realizarTarea() {
	Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation()
		.create();

	String guarnicionJson = llamarWebService(SERVER_URL + "/" + GUARNICIONES_SERVICE);
	List<Agregado> guarniciones = gson.fromJson(guarnicionJson,
		new TypeToken<List<Agregado>>() {
		}.getType());

	for (Agregado r : guarniciones) {
	    AgregadoBusiness.createOrUpdate(r);
	}
	
	return null;
    }

}
